package com.authentication.center.controller;

import com.authentication.center.common.LoadKey;
import lombok.extern.slf4j.Slf4j;
import org.springframework.util.Base64Utils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.security.KeyPair;
import java.util.HashMap;
import java.util.Map;

/**
 * @author : garvin
 * @version V1.0
 * @date : 2020年10月21日 10:20
 */
@Slf4j
@RestController
public class RsaKeyController {

    private LoadKey loadKey;

    public RsaKeyController(LoadKey loadKey) {
        this.loadKey = loadKey;
    }

    @GetMapping("/rsa/key")
    public Map<String, Object> getRsaKey() {
        KeyPair keyPair = loadKey.getKeyPair();
        String publicKey = Base64Utils.encodeToString(keyPair.getPublic().getEncoded());

        Map<String, Object> map = new HashMap<>(8);
        map.put("default", publicKey);
        return map;
    }
}
